package com.itxiao.controller;

import com.itxiao.annotation.Token;
import com.itxiao.config.SystemConfig;
import com.itxiao.pojo.bo.Page;
import com.itxiao.pojo.dto.AddCartDto;
import com.itxiao.pojo.dto.UpdateCartDto;
import com.itxiao.pojo.vo.R;
import com.itxiao.service.CartItemService;
import com.itxiao.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * (CartItem)表控制层
 *
 * @author makejava
 * @since 2025-10-12 17:07:24
 */
@RestController
@RequestMapping("admin/api/v1/cart")
@Api(tags = "购物车模块 ")
@CrossOrigin
public class CartItemController  {
    @Resource
    private CartItemService cartItemService;

    @ApiOperation("查询")
    @PostMapping("/list")
    @Token
    public R queryList(HttpServletRequest request) {
        return cartItemService.queryList(request.getHeader(SystemConfig.HEADER_TOKEN));
    }

    @ApiOperation("新增或者修改")
    @PostMapping("/addOrUpdate")
    @Token
    public R addOrUpdate(@RequestBody AddCartDto dto, HttpServletRequest request) {
        return cartItemService.addOrUpdate(dto,request.getHeader(SystemConfig.HEADER_TOKEN));
    }
    @ApiOperation("修改数量")
    @PostMapping("/update")
    @Token
    public R updateQuantity(@RequestBody UpdateCartDto dto, HttpServletRequest request) {
        return cartItemService.updateQuantity(dto,request.getHeader(SystemConfig.HEADER_TOKEN));
    }
    @ApiOperation("单个删除")
    @DeleteMapping("/delete/{id}")
    @Token
    public R deleteById(@PathVariable Integer id) {
        return R.ok(cartItemService.removeById(id));

    }

}

